#pragma once
#include "Event.hpp"

namespace Typhoon {
	template<class T,class Owner> class EventUpdater
	{
	public:
		EventUpdater();
		~EventUpdater();

		void SetOwner(Owner owner);

		void operator += (IDelegate<T>* handler);
		void operator -= (IDelegate<T>* handler);

		void operator () (T value);

		void Clear();

		int Count();
	
		Event<Owner> Added;
		Event<Owner> Removed;
	
	private:
		Event<T> event;
		Owner owner;

	};
}


template<class T, class Owner> Typhoon::EventUpdater<T, Owner>::EventUpdater() {
	
}

template<class T, class Owner> Typhoon::EventUpdater<T, Owner>::~EventUpdater() {
	Clear();
}

template<class T, class Owner> void Typhoon::EventUpdater<T, Owner>::SetOwner(Owner owner) {
	this->owner = owner;
}

template<class T, class Owner> void Typhoon::EventUpdater<T, Owner>::operator+=(IDelegate<T>* handler) {
	event+=handler;
	Added(owner);
}

template<class T, class Owner> void Typhoon::EventUpdater<T, Owner>::operator-=(IDelegate<T>* handler) {
	event-=handler;
	Removed(owner);
}

template<class T, class Owner> void Typhoon::EventUpdater<T, Owner>::operator() (T value) {
	event(value);
}

template<class T, class Owner> void Typhoon::EventUpdater<T, Owner>::Clear() {
	event.Clear();
}

template<class T, class Owner> int Typhoon::EventUpdater<T, Owner>::Count() {
	return event.Count();
}
